﻿
<%@ Page Title="" Language="C#" MasterPageFile="ReconSite.Master" AutoEventWireup="true" CodeBehind="CustomerMaster.aspx.cs" Inherits="Recon.Portal.WebUI.CustomerMaster" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleHolder" runat="server">
    <title>Customer Maintenance</title>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="BodyHolder" runat="server">
    <div class="formDiv" style="width:60%">
    <h2 class="formTitle">Customer Master</h2>
    <h1 class="formError" style="text-align:right;font-size:smaller;color:#CC2900;">Fields marked with * are mandatory</h1>
	<%--<span id="mandatoryMessage" class="formError">Fields marked with * are mandatory</span>--%>
    <table cellspacing="1" cellpadding="1" border="0" width = "100%">
       <%--<tr>
                <td align="right">
                    Option<span class="required">*</span></td>
                <td  colspan="3">                    
                    <asp:RadioButtonList ID="rbOption" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="True" OnSelectedIndexChanged="rbOption_SelectedIndexChanged">
                    <asp:ListItem Value="1" Selected="True">Add</asp:ListItem>
                    <asp:ListItem Value="2">Modify</asp:ListItem>
                    </asp:RadioButtonList>
                    <%--<asp:DropDownList ID="ddlOption" runat="server" 
                        AutoPostBack="false">
                        <asp:ListItem Value="0">Please Select</asp:ListItem>
                        <asp:ListItem Value="1">Add</asp:ListItem>
                        <asp:ListItem Value="2">Modify</asp:ListItem>
                    </asp:DropDownList>--%>
                    <%--<asp:RequiredFieldValidator ID="reqOption" runat="server" 
                        ErrorMessage="Mandatory" CssClass="formError"
                        ControlToValidate="ddlOption" InitialValue="0" 
                        SetFocusOnError="True"></asp:RequiredFieldValidator>--%>

              <%--  </td>
        </tr>--%>
        <tr>
            <td align="right">
                Customer ID<span class="required">*</span>
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtCustomerId" runat="server" MaxLength="10"></asp:TextBox>
                <%--<asp:Button ID="bntbrowse" runat="server" Text="..." Width="25px"   OnClick="bntbrowse_Click" CausesValidation="False" />
                <asp:Button ID="bntgetdetails" runat="server" Text="Get Details" OnClick="bntgetdetails_Click" CausesValidation="False" OnClientClick="javascript:return SelectUser();" />--%>
                <asp:RequiredFieldValidator ID="reqCusId" runat="server" 
                    ErrorMessage="Enter Customer Id" CssClass="formError"
                    ControlToValidate="txtCustomerId" InitialValue="" 
                    SetFocusOnError="True"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="regCusId" runat="server" 
                    ControlToValidate="txtCustomerId" CssClass="formError"
                    ErrorMessage="Invalid Customerid" ValidationExpression="^[0-9a-zA-Z]+$" 
                    SetFocusOnError="True"></asp:RegularExpressionValidator>
            </td>
        </tr>       
        <tr>
            
            <td align="right">
                Name<span class="required">*</span>
            </td>
            <td  colspan="3">
                <asp:TextBox ID="txtName" runat="server" MaxLength="100"></asp:TextBox>
               <asp:RequiredFieldValidator ID="reqName" runat="server" 
                    ErrorMessage="Enter Customer Name" CssClass="formError"
                    ControlToValidate="txtName" SetFocusOnError="True"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="regName" runat="server" 
                    ErrorMessage="Invalid name" CssClass="formError"
                    ControlToValidate="txtName" SetFocusOnError="True" 
                    ValidationExpression="^[a-zA-Z' '.]+$"></asp:RegularExpressionValidator>
                
            </td>
        </tr>
        
        <tr>
            <td align="right">
                Address1<span class="required">*</span>
            </td>
            <td>
                <asp:TextBox ID="txtAddress1" runat="server" MaxLength="50"></asp:TextBox>
                <asp:RequiredFieldValidator ID="reqAddress1" runat="server" 
                    ErrorMessage="Enter Address1" CssClass="formError"
                    ControlToValidate="txtAddress1" SetFocusOnError="True"></asp:RequiredFieldValidator>                    
            </td>
            <td align="right">
                Address2<span class="required">*</span>
            </td>
            <td>
                <asp:TextBox ID="txtAddress2" runat="server" MaxLength="50"></asp:TextBox>
               <asp:RequiredFieldValidator ID="reqaAddress2" runat="server" 
                    ErrorMessage="Enter Address2" CssClass="formError"
                    ControlToValidate="txtAddress2" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    
            </td>
        </tr>
       
        
        <tr>
          <td align="right">City<span class="required">*</span></td>
            <td> 
                <asp:TextBox ID="txtCity" runat="server" MaxLength="35"></asp:TextBox>
                <asp:RequiredFieldValidator ID="reqtxtCity" runat="server" 
                    ErrorMessage="Enter City" CssClass="formError"
                    ControlToValidate="txtCity" SetFocusOnError="True"></asp:RequiredFieldValidator>
               <asp:RegularExpressionValidator ID="regCity" runat="server" 
                    ControlToValidate="txtCity" CssClass="formError" 
                    ErrorMessage="Invalid city" SetFocusOnError="True" 
                    ValidationExpression="^[a-zA-Z' ']+$"></asp:RegularExpressionValidator>
              </td>
              <td align="right">State<span class="required">*</span></td>
            <td >  <asp:TextBox ID="txtState" runat="server" MaxLength="35"></asp:TextBox> 
                <asp:RequiredFieldValidator ID="reqState" runat="server" 
                    ErrorMessage="Enter State" CssClass="formError"
                    ControlToValidate="txtState" SetFocusOnError="True"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="regState" runat="server" 
                    ControlToValidate="txtState" CssClass="formError" 
                    ErrorMessage="Invalid State" SetFocusOnError="True" 
                    ValidationExpression="^[a-zA-Z' ']+$"></asp:RegularExpressionValidator>               
            </td>  
        </tr>
        <tr>
            <td align="right">
                Zip Code
            </td>
            <td >
                <asp:TextBox ID="txtZipCode" runat="server" MaxLength="10"></asp:TextBox>
                <asp:RegularExpressionValidator ID="regZipCode" runat="server" 
                    ErrorMessage="Invalid zip code" CssClass="formError"
                    ControlToValidate="txtZipCode" SetFocusOnError="True" 
                    ValidationExpression="^[1-9][0-9]{1,}$"></asp:RegularExpressionValidator>              
                
            </td>
            <td align="right">Country<span class="required">*</span></td>
            <td >
                <asp:TextBox ID="txtCountry" runat="server" MaxLength="35"></asp:TextBox>
                <asp:RequiredFieldValidator ID="reqCountry" runat="server" 
                    ErrorMessage="Enter Country" CssClass="formError"
                    ControlToValidate="txtCountry" SetFocusOnError="True" 
                        ></asp:RequiredFieldValidator>  
                <asp:RegularExpressionValidator ID="regCountry" runat="server" 
                    ControlToValidate="txtCountry" CssClass="formError" 
                    ErrorMessage="Invalid country" SetFocusOnError="True" 
                    ValidationExpression="^[a-zA-Z' ']+$"></asp:RegularExpressionValidator>
               
              </td>
        </tr>
       
        <tr>
            <td align="right">Phone</td>
            <td ><asp:TextBox ID="txtPhone" runat="server" Height="22px" MaxLength="15"></asp:TextBox>
                <asp:RegularExpressionValidator ID="regPhone" runat="server" 
                    ErrorMessage="Invalid phone" CssClass="formError"
                    ControlToValidate="txtPhone" SetFocusOnError="True" 
                    ValidationExpression="^[0-9]{1,}$"></asp:RegularExpressionValidator>
            </td>
            <td align="right">
                Email
            </td>
            <td  colspan="3">
                <asp:TextBox ID="txtEmail" runat="server" MaxLength="100"></asp:TextBox>
                <asp:RegularExpressionValidator ID="regTxtEmail" runat="server" 
                    ErrorMessage="Invalid email" CssClass="formError"
                    ControlToValidate="txtEmail" SetFocusOnError="True" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </td>
        </tr>
        
        <tr>
            <td align="right">
            </td>
            <td  colspan="3">
                
                <asp:CheckBox ID="chkIsenabled" runat="server" Checked="True" Text="Enable" />
               <%-- &nbsp;&nbsp; <asp:CheckBox ID="chkActive" runat="server" Text="Active" 
                    Checked="True" TabIndex="14" />--%>
            </td>
        </tr>
       
        <tr>
            <td >
                &nbsp;
            </td>
            <td  colspan="3">
                <asp:Button ID="btnSubmit" runat="server" Text="Add" onclick="btnSubmit_Click"/>
                &nbsp;&nbsp;<asp:Button ID="btnCancel" runat="server" Text="Reset" CausesValidation="False" 
                     onclick="btnCancel_Click" />
            </td>
        </tr>

           </table>
        <br />
         <div style="height:140px; width:100%; overflow:auto;">
                <asp:GridView ID="gvCustomer" runat="server" AllowPaging="false" 
                        AutoGenerateColumns="False" Width="100%"
                        HeaderStyle-BackColor="silver" HeaderStyle-ForeColor="#6f788f" 
                            HeaderStyle-Font-Bold="false" OnRowDeleting="gvCustAccount_RowDeleting">
                    <EmptyDataTemplate>
                        <asp:Label ID="lblNoRows" runat="server" Text="No records found for customer account detail." />
                    </EmptyDataTemplate>
                    <Columns>
                        <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:LinkButton  ID = "lnkSelect" runat="server"  Text = "Select"  CausesValidation="false" CommandName="Select"></asp:LinkButton>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Cust Id" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblCustomerID" runat="server" Text='<%# Eval("CustomerID") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblName" runat="server" Text='<%# Eval("CustomerName") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Address1" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblAddress1" runat="server" Text='<%# Eval("Address1") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Address2" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblAddress2" runat="server" Text='<%# Eval("Address2") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                         <asp:TemplateField HeaderText="City" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblCity" runat="server" Text='<%# Eval("City") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                         <asp:TemplateField HeaderText="State" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblState" runat="server" Text='<%# Eval("State") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                         <asp:TemplateField HeaderText="Zip Code" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblZipCode" runat="server" Text='<%# Eval("ZipCode") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                         <asp:TemplateField HeaderText="Country" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblCountry" runat="server" Text='<%# Eval("Country") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Phone" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblTelephoneNumber" runat="server" Text='<%# Eval("TelephoneNumber") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Email" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblEmailAddress" runat="server" Text='<%# Eval("EmailAddress") %>' ></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Enabled?" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label  ID = "lblIsEnabled" runat="server"  Text='<%# Eval("IsEnabled") %>'></asp:Label>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <%--<asp:CommandField HeaderText="Edit" ShowEditButton="True" CausesValidation="false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="Customer Id" DataField="CustomerID" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" ReadOnly="True"/>
                        <asp:BoundField HeaderText="Name" DataField="CustomerName" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="Address1" DataField="Address1" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center"/>
                        <asp:BoundField HeaderText="Address2" DataField="Address2" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="City" DataField="City" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="State" DataField="State" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="Zip Code" DataField="ZipCode" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="Phone" DataField="TelephoneNumber" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField HeaderText="Email" DataField="EmailAddress" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />
                        <asp:CheckBoxField HeaderText="Enabled?" DataField="IsEnabled" HeaderStyle-Font-Bold = "false" ItemStyle-HorizontalAlign="Center" />--%>
                        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ItemStyle-HorizontalAlign="Center"/>
                    </Columns>
                </asp:GridView>
                </div>


   <asp:UpdatePanel ID="upUnmatchedLists" runat="server" UpdateMode="Conditional">
        <ContentTemplate>    
                <div id="pnlMatchList" runat="server" class="pnlMatchList">    
                    <span style="azimuth: center;">
                        <div id="Div1" class="formDiv" runat ="server"  >
                            <center>
                                <asp:Label ID="lblMessage" runat="server"    CssClass="lable"/>
                            </center>
                        </div>
                    </span>
                    <div class="formDiv" style="width: 30%;">
                         <center>
                            <asp:Button ID="btnok" runat="server" Text="OK" onclick="btnok_Click" CausesValidation="False"  />
                          </center>
                    </div>
                </div>
            <div style="display: none">
                <asp:Button ID="btnManualPopup" runat="server" />
            </div>
            <ajax:ModalPopupExtender ID="btnClickPopup" runat="server" PopupControlID="pnlMatchList"
                TargetControlID="btnManualPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll" OkControlID = "btnok">
            </ajax:ModalPopupExtender>   
        </ContentTemplate>        
    </asp:UpdatePanel>
           </div>

            <script type="text/javascript">
                $(function () {
                    $("[id*=lnkSelect]").click(function () {
                        var tr = $(this).closest('tr');
                        //alert($(this).closest('tr').find('span[id*="lnkSelect"]').attr('Text'));
                        var custId = $(tr).find('span[id*="lblCustomerID"]').text();
                        var custName = $(tr).find('span[id*="lblName"]').text();
                        var address1 = $(tr).find('span[id*="lblAddress1"]').text();
                        var address2 = $(tr).find('span[id*="lblAddress2"]').text();
                        var city = $(tr).find('span[id*="lblCity"]').text();
                        var state = $(tr).find('span[id*="lblState"]').text();
                        var zipcode = $(tr).find('span[id*="lblZipCode"]').text();
                        var phone = $(tr).find('span[id*="lblTelephoneNumber"]').text();
                        var email = $(tr).find('span[id*="lblEmailAddress"]').text();
                        var country = $(tr).find('span[id*="lblCountry"]').text();
                        var isEnable = $(tr).find('span[id*="lblIsEnabled"]').text();
                        //var isEnable = $(tr).find('span[id*="lblIsEnabled"]').valueOf();
                        //var isEnable = $(tr).find('span[id*="lblIsEnabled"]').val();

                        $("#<%= txtCustomerId.ClientID %>").val(custId).text();
                        $("#<%= txtName.ClientID %>").val(custName).text();
                        $("#<%= txtAddress1.ClientID %>").val(address1).text();
                        $("#<%= txtAddress2.ClientID %>").val(address2).text();
                        $("#<%= txtCity.ClientID %>").val(city).text();
                        $("#<%= txtState.ClientID %>").val(state).text();
                        $("#<%= txtZipCode.ClientID %>").val(zipcode).text();
                        $("#<%= txtPhone.ClientID %>").val(phone).text();
                        $("#<%= txtEmail.ClientID %>").val(email).text();
                        $("#<%= txtCountry.ClientID %>").val(country).text();

                        var btntext ="Modify";
                        $("#<%= btnSubmit.ClientID %>").val(btntext).text();

                       if (isEnable.toString() == "True") {
                            $("#<%= chkIsenabled.ClientID %>").prop('checked', true);
                        }
                        else { $("#<%= chkIsenabled.ClientID %>").prop('checked', false); }

                        return false;


                       
            });
                 });

                function SelectUser() {
                    var Username = document.getElementById('<%=txtCustomerId.ClientID %>').value;
                    if (Username == '') {
                        alert("Customer Id is Mandatory");
                        return false;
                    }

                    return true;
                }
    </script>
</asp:Content>
